24 #ifndef MOTION_H_INCLUDED 25 #define MOTION_H_INCLUDED 29 #define FLAG_NOMINAL 2 30 #define FLAG_DECELERATING 4 31 #define FLAG_ACCELERATION_ENABLED 8 // unused 32 #define FLAG_CHECK_ENDSTOPS 16 33 #define FLAG_ALL_E_MOTORS 32 // For mixed extruder move all motors instead of selected motor 34 #define FLAG_SKIP_DEACCELERATING 64 // unused 35 #define FLAG_BLOCKED 128 38 #define FLAG_JOIN_STEPPARAMS_COMPUTED 1 40 #define FLAG_JOIN_END_FIXED 2 42 #define FLAG_JOIN_START_FIXED 4 44 #define FLAG_JOIN_START_RETRACT 8 46 #define FLAG_JOIN_END_RETRACT 16 48 #define FLAG_JOIN_NO_RETRACT 32 50 #define FLAG_JOIN_WAIT_EXTRUDER_UP 64 52 #define FLAG_JOIN_WAIT_EXTRUDER_DOWN 128 54 #if NONLINEAR_SYSTEM || defined(DOXYGEN) 102 return (dir &
YSTEP);
108 return (dir &
ZSTEP);
111 return (dir &
ESTEP);
123 return (dir & (
XSTEP << axis));
126 dir |=
XSTEP << axis;
140 #if CPU_ARCH == ARCH_ARM 168 #if NONLINEAR_SYSTEM || defined(DOXYGEN) 183 #if ENABLE_QUADRATIC_ADVANCE 186 int32_t advanceStart;
191 #ifdef DEBUG_STEPCOUNT 192 int32_t totalStepsRemaining;
273 #if MULTI_ZENDSTOP_HOMING 289 #if MAX_HARDWARE_ENDSTOP_Z 299 #if MAX_HARDWARE_ENDSTOP_Z 310 #if MAX_HARDWARE_ENDSTOP_Z 330 #if DRIVE_SYSTEM==XY_GANTRY || DRIVE_SYSTEM==YX_GANTRY 332 #elif DRIVE_SYSTEM==XZ_GANTRY || DRIVE_SYSTEM==ZX_GANTRY 339 #if DRIVE_SYSTEM==XY_GANTRY || DRIVE_SYSTEM==YX_GANTRY 346 #if DRIVE_SYSTEM==XZ_GANTRY || DRIVE_SYSTEM==ZX_GANTRY 380 return (dir &
XSTEP);
383 return (dir &
YSTEP);
392 return (dir &
ZSTEP);
395 return (dir &
ESTEP);
407 return (dir & (
XSTEP << axis));
410 dir |=
XSTEP << axis;
424 #if ENABLE_QUADRATIC_ADVANCE 427 for(uint8_t loop = 0; loop < max_loops; loop++) advanceTarget += advanceRate;
428 if(advanceTarget > advanceFull)
429 advanceTarget = advanceFull;
431 for(uint8_t loop = 0; loop < max_loops; loop++) advanceTarget -= advanceRate;
432 if(advanceTarget < advanceEnd)
433 advanceTarget = advanceEnd;
436 int tred = ((advanceTarget + h) >> 16);
439 if(tred > 0 && Printer::advanceStepsSet <= 0)
441 else if(tred < 0 && Printer::advanceStepsSet >= 0)
443 Printer::advanceStepsSet = tred;
450 if(tred > 0 && Printer::advanceStepsSet <= 0)
452 else if(tred < 0 && Printer::advanceStepsSet >= 0)
454 Printer::advanceStepsSet = tred;
460 if(stepsRemaining <= static_cast<int32_t>(decelSteps)) {
472 #if !(GANTRY) || defined(FAST_COREXYZ) 475 #if DRIVE_SYSTEM == XY_GANTRY || DRIVE_SYSTEM == XZ_GANTRY 484 #if DRIVE_SYSTEM == YX_GANTRY || DRIVE_SYSTEM == ZX_GANTRY 494 #ifdef DEBUG_STEPCOUNT 495 totalStepsRemaining--;
499 #if !(GANTRY) || DRIVE_SYSTEM == ZX_GANTRY || DRIVE_SYSTEM == XZ_GANTRY || defined(FAST_COREXYZ) 502 #if DRIVE_SYSTEM == XY_GANTRY 511 #if DRIVE_SYSTEM == YX_GANTRY 521 #ifdef DEBUG_STEPCOUNT 522 totalStepsRemaining--;
527 #if !(GANTRY) || DRIVE_SYSTEM == YX_GANTRY || DRIVE_SYSTEM == XY_GANTRY || defined(FAST_COREXYZ) 530 #if DRIVE_SYSTEM == XZ_GANTRY 539 #if DRIVE_SYSTEM == ZX_GANTRY 549 #ifdef DEBUG_STEPCOUNT 550 totalStepsRemaining--;
569 #if CPU_ARCH==ARCH_ARM 577 #if CPU_ARCH == ARCH_ARM 606 #if !NONLINEAR_SYSTEM || defined(DOXYGEN) 608 #if DISTORTION_CORRECTION || defined(DOXYGEN) 612 static void moveRelativeDistanceInSteps(int32_t x, int32_t y, int32_t z, int32_t e,
float feedrate,
bool waitEnd,
bool check_endstop,
bool pathOptimize =
true);
614 #if ARC_SUPPORT || defined(DOXYGEN) 615 static void arc(
float *position,
float *target,
float *offset,
float radius, uint8_t isclockwise);
623 #if NONLINEAR_SYSTEM || defined(DOXYGEN) 624 static uint8_t
queueNonlinearMove(uint8_t check_endstops, uint8_t pathOptimize, uint8_t softEndstop);
625 static inline void queueEMove(int32_t e_diff, uint8_t check_endstops, uint8_t pathOptimize);
628 static inline uint8_t
calculateDistance(
float axis_diff[], uint8_t dir,
float *distance);
629 #if (SOFTWARE_LEVELING && DRIVE_SYSTEM == DELTA) || defined(DOXYGEN) 630 static void calculatePlane(int32_t factors[], int32_t p1[], int32_t p2[], int32_t p3[]);
631 static float calcZOffset(int32_t factors[], int32_t pointX, int32_t pointY);
638 #endif // MOTION_H_INCLUDED static void computeMaxJunctionSpeed(PrintLine *previous, PrintLine *current)
Definition: motion.cpp:814
bool isZNegativeMove()
Definition: motion.h:89
int32_t error[E_AXIS_ARRAY]
Error calculation for Bresenham algorithm.
Definition: motion.h:155
void setParameterUpToDate()
Definition: motion.h:204
void setPositiveMoveOfAxis(uint8_t axis)
Definition: motion.h:128
void block()
Definition: motion.h:234
bool isCheckEndstops()
Definition: motion.h:246
uint32_t fAcceleration
accelerationPrim*262144/F_CPU
Definition: motion.h:178
bool isEndSpeedFixed()
Definition: motion.h:216
static void allowInterrupts()
Definition: HAL.h:568
uint8_t getWaitForXLinesFilled()
Definition: motion.h:225
static INLINE void pushLine()
Definition: motion.h:585
static void queueCartesianSegmentTo(uint8_t check_endstops, uint8_t pathOptimize)
Definition: motion.cpp:201
float minSpeed
Definition: motion.h:166
bool isYNegativeMove()
Definition: motion.h:83
ufast8_t joinFlags
Definition: motion.h:147
float endSpeed
Exit speed in mm/s.
Definition: motion.h:165
INLINE void startYStep()
Definition: motion.h:498
bool isXOrZMove()
Definition: motion.h:388
bool isXOrYMove()
Definition: motion.h:385
#define YSTEP
Definition: Repetier.h:190
#define E_STEP_DIRPOS
Definition: Repetier.h:197
static uint8_t calculateDistance(float axis_diff[], uint8_t dir, float *distance)
static void forwardPlanner(ufast8_t p)
Definition: motion.cpp:1000
static INLINE uint8_t isPrinting()
Definition: Printer.h:743
static INLINE void startYStep()
Definition: Printer.h:944
void setXYMoveFinished()
Definition: motion.h:71
ticks_t fullInterval
interval at full speed in ticks/step.
Definition: motion.h:174
static INLINE bool yMin()
Definition: Endstops.h:101
#define PRINTLINE_CACHE_SIZE
Number of moves we can cache in advance.
Definition: Configuration.h:1247
#define FLAG_NOMINAL
Definition: motion.h:29
float accelerationDistance2
Real 2.0*distance*acceleration mm²/s²
Definition: motion.h:162
bool isZNegativeMove()
Definition: motion.h:370
bool areParameterUpToDate()
Definition: motion.h:198
static PrintLine lines[]
Cache for print moves.
Definition: motion.h:145
bool isYNegativeMove()
Definition: motion.h:364
float speedX
Speed in x direction at fullInterval in mm/s.
Definition: motion.h:156
static PrintLine * cur
Current printing line.
Definition: motion.h:196
static INLINE void nextPlannerIndex(ufast8_t &p)
Definition: motion.h:620
void setStartSpeedFixed(bool newState)
Definition: motion.h:210
static INLINE bool zMax()
Definition: Endstops.h:122
static volatile int extruderStepsNeeded
This many extruder steps are still needed, <0 = reverse steps needed.
Definition: Printer.h:238
float speedE
Speed in E direction at fullInterval in mm/s.
Definition: motion.h:159
static void LaserWarmUp(uint32_t wait)
Definition: motion.cpp:1118
static uint32_t mulu16xu16to32(unsigned int a, unsigned int b)
Definition: HAL.h:445
void setXYMoveFinished()
Definition: motion.h:352
bool isXNegativeMove()
Definition: motion.h:77
#define FLAG_DECELERATING
Definition: motion.h:30
void setPositiveDirectionForAxis(uint8_t axis)
Definition: motion.h:412
#define XY_STEP
Definition: Repetier.h:195
speed_t vStart
Starting speed in steps/s.
Definition: motion.h:180
bool isMoveOfAxis(uint8_t axis)
Definition: motion.h:406
bool isXNegativeMove()
Definition: motion.h:358
static int8_t motorYorZ
Definition: Printer.h:378
float speedY
Speed in y direction at fullInterval in mm/s.
Definition: motion.h:157
static INLINE uint8_t isAdvanceActivated()
Definition: Printer.h:609
void updateAdvanceSteps(speed_t v, uint8_t max_loops, bool accelerate)
Definition: motion.h:421
#define XYZE_STEP
Definition: Repetier.h:196
uint8_t numNonlinearSegments
Number of delta segments left in line. Decremented by stepper timer.
Definition: motion.h:169
static uint8_t queueNonlinearMove(uint8_t check_endstops, uint8_t pathOptimize, uint8_t softEndstop)
uint8_t flag8_t
Definition: HAL.h:159
static void arc(float *position, float *target, float *offset, float radius, uint8_t isclockwise)
Definition: motion.cpp:2049
static unsigned int mulu6xu16shift16(unsigned int a, unsigned int b)
Definition: HAL.h:472
void invalidateParameter()
Definition: motion.h:201
int32_t stepsRemaining
Remaining steps, until move is finished.
Definition: motion.h:195
secondspeed_t secondSpeed
Definition: motion.h:149
#define FLAG_WARMUP
Definition: motion.h:28
static PrintLine * getNextWriteLine()
Definition: motion.h:595
uint16_t speed_t
Definition: HAL.h:156
static void resetPathPlanner()
Definition: motion.h:415
bool isMoveOfAxis(uint8_t axis)
Definition: motion.h:122
static INLINE void previousPlannerIndex(ufast8_t &p)
Definition: motion.h:617
void setNominalMove()
Definition: motion.h:252
bool isZPositiveMove()
Definition: motion.h:367
bool isStartSpeedFixed()
Definition: motion.h:207
bool isNoMove()
Definition: motion.h:116
#define FLAG_CHECK_ENDSTOPS
Definition: motion.h:32
void setYMoveFinished()
Definition: motion.h:65
static INLINE uint8_t isHoming()
Definition: Printer.h:766
static INLINE bool z2MinMax()
Definition: Endstops.h:129
#define FLAG_JOIN_END_FIXED
Definition: motion.h:40
bool isZMove()
Definition: motion.h:107
void setZMoveFinished()
Definition: motion.h:345
bool isXMove()
Definition: motion.h:379
static INLINE bool yMax()
Definition: Endstops.h:108
static INLINE bool xMin()
Definition: Endstops.h:87
float startSpeed
Starting speed in mm/s.
Definition: motion.h:164
INLINE void startZStep()
Definition: motion.h:526
static INLINE void setCurrentLine()
Definition: motion.h:567
static void updateTrapezoids()
Definition: motion.cpp:669
bool isXYZMove()
Definition: motion.h:119
static INLINE void setMenuMode(uint16_t mode, bool on)
Definition: Printer.h:401
bool isZPositiveMove()
Definition: motion.h:86
int32_t timeInTicks
Definition: motion.h:153
uint8_t secondspeed_t
Definition: Repetier.h:217
static float calcZOffset(int32_t factors[], int32_t pointX, int32_t pointY)
NonlinearSegment segments[DELTASEGMENTS_PER_PRINTLINE]
Definition: motion.h:172
static Extruder * current
Definition: Extruder.h:233
bool isZMove()
Definition: motion.h:391
bool isYMove()
Definition: motion.h:101
static void waitForXFreeLines(uint8_t b=1, bool allowMoves=false)
Definition: motion.cpp:1149
static uint32_t stepNumber
Step number in current move.
Definition: Printer.h:272
#define XYZ_STEP
Definition: Repetier.h:194
bool isBlocked()
Definition: motion.h:240
static void calculatePlane(int32_t factors[], int32_t p1[], int32_t p2[], int32_t p3[])
#define FLAG_ALL_E_MOTORS
Definition: motion.h:33
static INLINE void startZStep()
Definition: Printer.h:950
static void moveRelativeDistanceInSteps(int32_t x, int32_t y, int32_t z, int32_t e, float feedrate, bool waitEnd, bool check_endstop, bool pathOptimize=true)
Definition: motion.cpp:104
void setWaitForXLinesFilled(uint8_t b)
Definition: motion.h:228
static uint8_t getLinesCount()
Definition: motion.h:591
fast8_t primaryAxis
Definition: motion.h:151
void setZMoveFinished()
Definition: motion.h:68
#define TOWER_ARRAY
Definition: Repetier.h:134
static INLINE bool xMax()
Definition: Endstops.h:94
bool isYPositiveMove()
Definition: motion.h:80
static fast8_t multiZHomeFlags
Definition: Printer.h:369
bool isWarmUp()
Definition: motion.h:222
void setPositiveDirectionForAxis(uint8_t axis)
Definition: motion.h:131
static int8_t motorX
Definition: Printer.h:377
bool isNominalMove()
Definition: motion.h:249
static INLINE bool zProbe()
Definition: Endstops.h:136
float invFullSpeed
1.0/fullSpeed for faster computation
Definition: motion.h:161
bool isEMove()
Definition: motion.h:110
bool isAllEMotors()
Definition: motion.h:243
void setXMoveFinished()
Definition: motion.h:329
void setEndSpeedFixed(bool newState)
Definition: motion.h:219
uint8_t ufast8_t
Definition: HAL.h:161
bool isXPositiveMove()
Definition: motion.h:74
bool isXMove()
Definition: motion.h:98
bool isEPositiveMove()
Definition: motion.h:92
static int32_t bresenhamStep()
Definition: motion.cpp:2545
static INLINE bool isZProbingActive()
Definition: Printer.h:848
bool isExtruderForwardMove()
Definition: motion.h:231
static volatile bool nlFlag
Definition: motion.h:141
uint32_t decelSteps
How much steps does it take, to reach the end speed.
Definition: motion.h:176
#define DELTASEGMENTS_PER_PRINTLINE
Number of delta moves in each line. Moves that exceed this figure will be split into multiple lines...
Definition: Configuration.h:1077
void logLine()
Definition: motion.cpp:1129
INLINE void startXStep()
Definition: motion.h:471
bool isXYZMove()
Definition: motion.h:403
static INLINE bool zMin()
Definition: Endstops.h:115
bool isYMove()
Definition: motion.h:382
#define FLAG_JOIN_STEPPARAMS_COMPUTED
Definition: motion.h:38
static ufast8_t linesPos
Position for executing line movement.
Definition: motion.h:144
INLINE bool moveAccelerating()
Definition: motion.h:468
static INLINE void startXStep()
Definition: Printer.h:923
bool isEPositiveMove()
Definition: motion.h:373
static void calculateDirectionAndDelta(int32_t difference[], ufast8_t *dir, int32_t delta[])
static int advanceStepsSet
Definition: Printer.h:241
float maxJunctionSpeed
Max. junction speed between this and next segment.
Definition: motion.h:163
speed_t vEnd
End speed in steps/s.
Definition: motion.h:181
static void forbidInterrupts()
Definition: HAL.h:576
bool isXOrYMove()
Definition: motion.h:104
int32_t delta[E_AXIS_ARRAY]
Steps we want to move.
Definition: motion.h:154
flag8_t dir
Direction of delta movement.
Definition: motion.h:59
float safeSpeed(fast8_t drivingAxis)
Definition: motion.cpp:1056
void setMoveOfAxis(uint8_t axis)
Definition: motion.h:409
static volatile ufast8_t linesCount
Number of lines cached 0 = nothing to do.
Definition: motion.h:197
bool isEMove()
Definition: motion.h:394
#define FLAG_BLOCKED
Definition: motion.h:35
static INLINE void removeCurrentLineForbidInterrupt()
Definition: motion.h:574
bool isENegativeMove()
Definition: motion.h:376
ufast8_t dir
Direction of movement. 1 = X+, 2 = Y+, 4= Z+, values can be combined.
Definition: motion.h:152
static void queueCartesianMove(uint8_t check_endstops, uint8_t pathOptimize)
Definition: motion.cpp:321
static long advanceExecuted
Executed advance steps.
Definition: Printer.h:243
static INLINE bool hasLines()
Definition: motion.h:564
int8_t fast8_t
Definition: HAL.h:160
#define INLINE
Definition: HAL.h:37
INLINE void setWaitTicks(long wait)
Definition: motion.h:560
speed_t vMax
Maximum reached speed in steps/s.
Definition: motion.h:179
#define MENU_MODE_PRINTING
Definition: Repetier.h:556
static void backwardPlanner(ufast8_t p, ufast8_t last)
Definition: motion.cpp:949
volatile ufast8_t flags
Definition: motion.h:148
#define ZSTEP
Definition: Repetier.h:191
uint32_t ticks_t
Definition: HAL.h:157
uint8_t moveID
ID used to identify moves which are all part of the same line.
Definition: motion.h:170
void calculateMove(float axis_diff[], uint8_t pathOptimize, fast8_t distanceBase)
Definition: motion.cpp:466
void fixStartAndEndSpeed()
Definition: motion.h:213
INLINE long getWaitTicks()
Definition: motion.h:557
#define FLAG_JOIN_START_FIXED
Definition: motion.h:42
static void queueEMove(int32_t e_diff, uint8_t check_endstops, uint8_t pathOptimize)
bool isYPositiveMove()
Definition: motion.h:361
#define Z_STEP_DIRPOS
Definition: Repetier.h:200
#define Y_STEP_DIRPOS
Definition: Repetier.h:198
float distance
Definition: motion.h:167
#define E_AXIS_ARRAY
Definition: Repetier.h:127
static void update()
Definition: Endstops.cpp:35
bool isEOnlyMove()
Definition: motion.h:113
#define ESTEP
Definition: Repetier.h:192
void setMoveOfAxis(uint8_t axis)
Definition: motion.h:125
bool isENegativeMove()
Definition: motion.h:95
static uint32_t timer
used for acceleration/deceleration timing
Definition: Printer.h:271
uint32_t accelerationPrim
Acceleration along primary axis.
Definition: motion.h:177
uint32_t accelSteps
How much steps does it take, to reach the plateau.
Definition: motion.h:175
#define XSTEP
Definition: Repetier.h:189
void setYMoveFinished()
Definition: motion.h:338
#define X_DIRPOS
Definition: Repetier.h:183
bool isXPositiveMove()
Definition: motion.h:355
bool isNoMove()
Definition: motion.h:400
#define X_STEP_DIRPOS
Definition: Repetier.h:199
INLINE bool moveDecelerating()
Definition: motion.h:459
void checkEndstops()
Definition: motion.h:255
bool isEOnlyMove()
Definition: motion.h:397
void updateStepsParameter()
Definition: motion.cpp:897
void setXMoveFinished()
Definition: motion.h:62
int32_t numPrimaryStepPerSegment
Number of primary Bresenham axis steps in each delta segment.
Definition: motion.h:171
static int32_t stepsRemainingAtZHit
Definition: Printer.h:308
float speedZ
Speed in z direction at fullInterval in mm/s.
Definition: motion.h:158
uint16_t calculateNonlinearSubSegments(uint8_t softEndstop)
static void moveRelativeDistanceInStepsReal(int32_t x, int32_t y, int32_t z, int32_t e, float feedrate, bool waitEnd, bool pathOptimize=true)
Definition: motion.cpp:159
float fullSpeed
Desired speed mm/s.
Definition: motion.h:160
void unblock()
Definition: motion.h:237
static uint8_t insertWaitMovesIfNeeded(uint8_t pathOptimize, uint8_t waitExtraLines)
Definition: motion.cpp:1090
static ufast8_t linesWritePos
Position where we write the next cached line move.
Definition: motion.h:146
static INLINE bool anyEndstopHit()
Definition: Endstops.h:68